package com.th.supcom.pds.recipefee.client.widget;

import java.util.List;

import com.extjs.gxt.ui.client.store.ListStore;
import com.extjs.gxt.ui.client.widget.MessageBox;
import com.extjs.gxt.ui.client.widget.form.ComboBox;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.th.supcom.pds.auditprescription.client.model.PdsPrescDetailCombineModel;
import com.th.supcom.pds.common.client.model.OfficeModel;
import com.th.supcom.pds.recipefee.client.service.RecipeFeeRpc;
import com.th.supcom.pds.recipefee.client.service.RecipeFeeRpcAsync;

public class OrgCombox extends ComboBox <OfficeModel>
{
    /**
     * 公司版权信息.
     */
    public static final String copyright = "Copyright 2014, Carefx Corporation";

    /**
     * 提交路径.
     */
    public static final String SCC_BRANCH = "$URL$";

    /**
     * 提交日期.
     */
    public static final String SCC_LAST_MODIFICATION_DATE = "$Date$";

    /**
     * 最终修改人员.
     */
    public static final String SCC_LAST_MODIFIER_NAME = "$Author$";

    /**
     * 最终版本号.
     */
    public static final String SCC_REVISION = "$Revision$";

    private final RecipeFeeRpcAsync m_recipeFeeRpcAsync = GWT.create (RecipeFeeRpc.class);

    public OrgCombox ()
    {
        store = new ListStore <OfficeModel> ();
        super.setDisplayField ("name");
        super.setTriggerAction (TriggerAction.ALL);
        super.setWidth (width);
    }

    public void loadData (final PdsPrescDetailCombineModel pdsPrescDetailCombine)
    {
        m_recipeFeeRpcAsync.findExecuteOffice (pdsPrescDetailCombine, new AsyncCallback <List <OfficeModel>> ()
        {

            @Override
            public void onFailure (final Throwable caught)
            {
                MessageBox.alert ("警告", caught.getMessage (), null);
                return;
            }

            @Override
            public void onSuccess (final List <OfficeModel> result)
            {
                store.removeAll ();
                store.add (result);
            }
        });
    }
}
